package com.fizz.service;

import com.fizz.config.ReadDataSource;
import com.fizz.config.WriteDataSource;
import com.fizz.mapper.DemoMapper;
import com.fizz.model.Demo;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DemoServiceImpl {

    @Autowired
    private SqlSessionFactory sqlSessionFactory;


    @WriteDataSource
    public void insert(){
        DemoMapper mapper = sqlSessionFactory.openSession().getMapper(DemoMapper.class);
        mapper.testInsert();

    }


    @ReadDataSource
    public Demo get(){
        DemoMapper demoMapper = sqlSessionFactory.openSession().getMapper(DemoMapper.class);
        Demo demo = demoMapper.selectDemo();
        return demo;
    }
}
